//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "MarketModelBasisSystem.h"
using namespace Cephei::QL::Models::Marketmodels::Callability;
#include <gen/QL/Models/Marketmodels/EvolutionDescription.h>
#include <gen/QL/Models/Marketmodels/CurveState.h>
#include <gen/QL/Models/Marketmodels/Callability/MarketModelNodeDataProvider.h>
using namespace Cephei::QL::Models::Marketmodels;
#undef HANDLE
#define ABSTRACT
#undef STRUCT
Cephei::QL::Models::Marketmodels::Callability::CMarketModelBasisSystem::CMarketModelBasisSystem (boost::shared_ptr<QuantLib::MarketModelBasisSystem>& childNative, Object^ owner) : CMarketModelNodeDataProvider(CMarketModelBasisSystem::typeid)
{
#ifdef HANDLE
	_phMarketModelBasisSystem = NULL;
#endif
	_ppMarketModelBasisSystem = &childNative;
    _ppMarketModelNodeDataProvider = new boost::shared_ptr<QuantLib::MarketModelNodeDataProvider> (boost::dynamic_pointer_cast<QuantLib::MarketModelNodeDataProvider> (*_ppMarketModelBasisSystem));
}
Cephei::QL::Models::Marketmodels::Callability::CMarketModelBasisSystem::CMarketModelBasisSystem (QuantLib::MarketModelBasisSystem& childNative, Object^ owner) : CMarketModelNodeDataProvider(CMarketModelBasisSystem::typeid)
{
#ifdef HANDLE
	_phMarketModelBasisSystem = NULL;
#endif
	_ppMarketModelBasisSystem = new boost::shared_ptr<QuantLib::MarketModelBasisSystem> (&childNative);
    _ppMarketModelNodeDataProvider = new boost::shared_ptr<QuantLib::MarketModelNodeDataProvider> (boost::dynamic_pointer_cast<QuantLib::MarketModelNodeDataProvider> (*_ppMarketModelBasisSystem));
    _MarketModelBasisSystemOwner = owner;
    _MarketModelNodeDataProviderOwner = owner;
}

Cephei::QL::Models::Marketmodels::Callability::CMarketModelBasisSystem::CMarketModelBasisSystem (CMarketModelBasisSystem^ copy) : CMarketModelNodeDataProvider(CMarketModelBasisSystem::typeid)
{
#ifdef HANDLE
	_phMarketModelBasisSystem = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppMarketModelBasisSystem = new boost::shared_ptr<QuantLib::MarketModelBasisSystem> (copy->GetShared());
        _ppMarketModelNodeDataProvider = new boost::shared_ptr<QuantLib::MarketModelNodeDataProvider> (boost::dynamic_pointer_cast<QuantLib::MarketModelNodeDataProvider> (*_ppMarketModelBasisSystem));
    }
}
Cephei::QL::Models::Marketmodels::Callability::CMarketModelBasisSystem::CMarketModelBasisSystem (System::Type^ t) : CMarketModelNodeDataProvider(CMarketModelBasisSystem::typeid)
{
#ifdef HANDLE
	_phMarketModelBasisSystem = NULL;
#endif
	if (!t->IsSubclassOf(CMarketModelBasisSystem::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Models::Marketmodels::Callability::CMarketModelBasisSystem::CMarketModelBasisSystem (QuantLib::Handle<QuantLib::MarketModelBasisSystem>& childNative, Object^ owner)  : CMarketModelNodeDataProvider(CMarketModelBasisSystem::typeid)
{
	_phMarketModelBasisSystem = &childNative;
	_ppMarketModelBasisSystem = &static_cast<boost::shared_ptr<QuantLib::MarketModelBasisSystem>>(childNative.currentLink());
    _ppMarketModelNodeDataProvider = new boost::shared_ptr<QuantLib::MarketModelNodeDataProvider> (boost::dynamic_pointer_cast<QuantLib::MarketModelNodeDataProvider> (*_ppMarketModelBasisSystem));
    _MarketModelBasisSystemOwner = owner;
}
Cephei::QL::Models::Marketmodels::Callability::CMarketModelBasisSystem::CMarketModelBasisSystem (QuantLib::Handle<QuantLib::MarketModelBasisSystem> childNative)  : CMarketModelNodeDataProvider(CMarketModelBasisSystem::typeid)
{
	_phMarketModelBasisSystem = &childNative;
	_ppMarketModelBasisSystem = &static_cast<boost::shared_ptr<QuantLib::MarketModelBasisSystem>>(childNative.currentLink());
    _ppMarketModelNodeDataProvider = new boost::shared_ptr<QuantLib::MarketModelNodeDataProvider> (boost::dynamic_pointer_cast<QuantLib::MarketModelNodeDataProvider> (*_ppMarketModelBasisSystem));
}
#endif
#ifdef STRUCT
Cephei::QL::Models::Marketmodels::Callability::CMarketModelBasisSystem::CMarketModelBasisSystem (QuantLib::MarketModelBasisSystem childNative)  : CMarketModelNodeDataProvider(CMarketModelBasisSystem::typeid)
{
#ifdef HANDLE
	_phMarketModelBasisSystem = NULL;
#endif
	_ppMarketModelBasisSystem = new boost::shared_ptr<QuantLib::MarketModelBasisSystem> (new QuantLib::MarketModelBasisSystem (childNative));
    _ppMarketModelNodeDataProvider = new boost::shared_ptr<QuantLib::MarketModelNodeDataProvider> (boost::dynamic_pointer_cast<QuantLib::MarketModelNodeDataProvider> (*_ppMarketModelBasisSystem));
}
#endif

Cephei::QL::Models::Marketmodels::Callability::CMarketModelBasisSystem::~CMarketModelBasisSystem ()
{
    if (_ppMarketModelBasisSystem != NULL)
    {
	    delete _ppMarketModelBasisSystem;
        _ppMarketModelBasisSystem = NULL;
    }
}
Cephei::QL::Models::Marketmodels::Callability::CMarketModelBasisSystem::!CMarketModelBasisSystem ()
{
    if (_ppMarketModelBasisSystem != NULL)
    {
	    delete _ppMarketModelBasisSystem;
    }
}
QuantLib::MarketModelBasisSystem& Cephei::QL::Models::Marketmodels::Callability::CMarketModelBasisSystem::GetReference ()
{
    if (_ppMarketModelBasisSystem == NULL) throw gcnew NativeNullException ();
	return **_ppMarketModelBasisSystem;
}
boost::shared_ptr<QuantLib::MarketModelBasisSystem>& Cephei::QL::Models::Marketmodels::Callability::CMarketModelBasisSystem::GetShared ()
{
    if (_ppMarketModelBasisSystem == NULL) throw gcnew NativeNullException ();
	return *_ppMarketModelBasisSystem;
}
QuantLib::MarketModelBasisSystem* Cephei::QL::Models::Marketmodels::Callability::CMarketModelBasisSystem::GetPointer ()
{
    if (_ppMarketModelBasisSystem == NULL) throw gcnew NativeNullException ();
	return &**_ppMarketModelBasisSystem;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::MarketModelBasisSystem>& Cephei::QL::Models::Marketmodels::Callability::CMarketModelBasisSystem::GetHandle ()
{
	if (_phMarketModelBasisSystem == NULL)
	{
		_phMarketModelBasisSystem = new Handle<QuantLib::MarketModelBasisSystem> (*_ppMarketModelBasisSystem);
	}
	return *_phMarketModelBasisSystem;
}
#endif
bool Cephei::QL::Models::Marketmodels::Callability::CMarketModelBasisSystem::HasNative () 
{
	return (_ppMarketModelBasisSystem != NULL);
}

Cephei::IVector<UInt64>^ Cephei::QL::Models::Marketmodels::Callability::CMarketModelBasisSystem::NumberOfData::get ()
{
    try
    {
    	std::vector<QuantLib::Size> _rv = (std::vector<QuantLib::Size>)(*_ppMarketModelBasisSystem)->numberOfData ( );   
        Cephei::IVector<UInt64>^ _nrv = gcnew CoVector<UInt64> (gcnew CUInt64Vector (_rv));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::IVector<UInt64>^ Cephei::QL::Models::Marketmodels::Callability::CMarketModelBasisSystem::NumberOfFunctions::get ()
{
    try
    {
    	std::vector<QuantLib::Size> _rv = (std::vector<QuantLib::Size>)(*_ppMarketModelBasisSystem)->numberOfFunctions ( );   
        Cephei::IVector<UInt64>^ _nrv = gcnew CoVector<UInt64> (gcnew CUInt64Vector (_rv));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

